/*
 * @Description:
 * @Version: 2.0
 * @Autor: Seven
 * @Date: 2023-12-11 16:02:35
 * @LastEditors: Seven
 * @LastEditTime: 2023-12-18 17:03:27
 */
import React from "react";
import { Modal } from "antd";
import axios from "axios";

export default function RecordModal({
  isModalOpen,
  handleRecodeCancel,
  recodeData,
}) {
  const onFinish = () => {
    let data = {};
    let NodeListEl = document.querySelectorAll("input");
    let NodeListTextareaEl = document.querySelectorAll("textarea");

    for (let i = 0; i < NodeListEl.length; i++) {
      let inpEl = NodeListEl[i].name;
      data[inpEl] = NodeListEl[i].value;
    }
    for (let i = 0; i < NodeListTextareaEl.length; i++) {
      let TextEl = NodeListTextareaEl[i].name;
      data[TextEl] = NodeListTextareaEl[i].value;
    }
    axios({
      method: "POST",
      url: `http://192.168.200.129:8081/wordDoc/addRecord`,
      data: { ...data, templateId: recodeData.id },
      timeout: 30000,
    })
      .then((res) => {
        if (res.data.code === 200) {
          handleRecodeCancel && handleRecodeCancel();
        }
      })
      .catch((err) => {
        console.log(err);
      });
  };

  return (
    <div>
      <Modal
        title="新增记录"
        open={isModalOpen}
        destroyOnClose
        onOk={onFinish}
        onCancel={handleRecodeCancel}
        width="760px"
      >
        <div>
          <div>
            名称：
            <input
              type="text"
              name="name"
              className="name"
              style={{ marginRight: "50px", height: "30px" }}
            />
            分类：
            <input
              type="text"
              name="cate"
              className="cate"
              style={{ height: "30px" }}
            />
          </div>
        </div>
        <div dangerouslySetInnerHTML={{ __html: recodeData?.inputHtml }}></div>
      </Modal>
    </div>
  );
}
